﻿using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wenku8.Entity;
using wenku8.Enum;

namespace wenku8.Parser
{
    public class IllustrationUriParser
    {
        public static async void GetIllustrationsAsync(string htmlPage, ObservableCollection<Illustration> illustrations)
        {
            var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(htmlPage);
            var contentNode = htmlDoc.DocumentNode;
            foreach (var imageNode in contentNode.Descendants("img")) {
                var illustration = new Illustration
                {
                    Image = await ImageHelper.GetImage(new System.Uri(imageNode.Attributes["src"].Value), ImageType.Illustration)
                };
                illustrations.Add(illustration);
            }
        }
    }
}
